#include <iostream>
#include <iomanip>

#include "./TestSetBase.h"


/** every testset unit should export this */
extern TestSetBase exported_testset;


int main(const int argc, const char **argv)
{
    using namespace std;

    /* run test */
    exported_testset();

    /* print result */
    const auto print_testset_result = [&] (std::ostream &os)
    {
        os << std::left;
        os << "Testset: " << exported_testset.name << std::endl;
        
        printf("%32s%16s%16s%16s%16s%16s\n", 
          "test case", "thread count", "total time(s)", "total ops", "iops", "lat(us)"
        );
        os << std::string(24+16+16+16+16+16, '-') << std::endl;

        for (const auto &c : exported_testset.test_cases) {
            const double total_time = static_cast<double>(c->executed_timespan.count()) / 1e9;
            const double total_ops = static_cast<double>(c->executed_times);
            printf("%32s%16d%16f%16.0f%16.0f%16.2f\n",
              c->name.c_str(),
              c->thread_nr,
              total_time,
              total_ops,
              total_ops / total_time,
              total_time * c->thread_nr / total_ops * 1e6 
            );
        }
    };
    print_testset_result(std::cout);
    // TODO may print to file

    return 0;
}
